﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharedGenomics.TextMining
{
    public class ScoredTerm : IComparable<ScoredTerm>
    {
        #region Private Members

        private string _term;
        private double _cValue;

        #endregion

        #region Constructors

        public ScoredTerm(string term, double cValue)
        {
            this.Term = term;
            this.CValue = cValue;
        }

        #endregion

        #region Public Methods

        public override bool Equals(object obj)
        {
            ScoredTerm comp = obj as ScoredTerm;
            return (comp != null && this.CValue == comp.CValue && String.Equals(this.Term, comp.Term));
        }

        public override int GetHashCode()
        {
            return this.CValue.GetHashCode();
        }

        #endregion

        #region Properties

        public string Term
        {
            get { return this._term; }
            private set { this._term = value; }
        }

        public double CValue
        {
            get { return this._cValue; }
            private set { this._cValue = value; }
        }

        public IList<string> Words
        {
            get
            {
                return this._term == null ? new List<string>() : new List<string>(this._term.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            }
        }

        #endregion

        #region IComparable<ScoredTerm> Members

        public int CompareTo(ScoredTerm other)
        {
            return this.CValue.CompareTo(other.CValue);
        }

        #endregion
    }
}
